package com.yangc.stream.rabbit.consumer;

import com.yangc.stream.rabbit.entity.DemoMessage;
import org.slf4j.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Component
public class DemoConsumer {

    Logger logger = org.slf4j.LoggerFactory.getLogger(DemoConsumer.class);
    // 消费者组1，带重试
    @Bean
    public Consumer<DemoMessage> consumer1() {
        return message -> {
            logger.info("[consumer1] 收到消息：{}", message);
            if (message.content().contains("error")) {
                throw new RuntimeException("模拟异常，触发重试");
            }
        };
    }

    // 消费者组2
    @Bean
    public Consumer<DemoMessage> consumer2() {
        return message -> {
            logger.info("[consumer2] 收到消息：{}", message);
        };
    }

    // 延迟消费者
    @Bean
    public Consumer<DemoMessage> delayConsumer() {
        return message -> {
            logger.info("[delayConsumer] 延迟收到消息：{}", message);
        };
    }
}
